//using Microsoft.VisualBasic;
using System;
using System.Text;
using System.Runtime.InteropServices;
static class Module1
{
    [DllImport("arrBstr", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
    public static extern int bstrToarr(ref byte vbstr, ref float p, int n);
    [DllImport("arrBstr", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
    public static extern int arrTobstr(ref byte b, ref float v, int n);
	public struct Sig
	{
        //public object xArr;
        //public int xn;
        //[VBFixedArray(4)]
        //public object[] yArr;
        //[VBFixedArray(4)]
        //public int[] yn;
        //[VBFixedArray(4)]
        //public bool[] stoped;
        //[VBFixedArray(4)]

        //public bool[] Aborted;
        //public void Initialize()
        //{
        //     // ERROR: Not supported in C#: ReDimStatement

        //     // ERROR: Not supported in C#: ReDimStatement

        //     // ERROR: Not supported in C#: ReDimStatement

        //     // ERROR: Not supported in C#: ReDimStatement

        //}
	}
	public static byte[] SingleArrTobyteArr(ref object v, ref int n)
	{
		byte[] b = null;
		b = new byte[2];
		//'Dim r As Integer
		//If n < 1 Then
		//    Return b
		//Else
		//    ReDim b(4 * n)
		//    'mymemcpy(b(0), v, n * 4)
		//    arrTobstr(b, v, n)
		//End If
		return b;
	}
	public static void savesignew_memo(ref NHibernate.ISession session, ref Sig mysig, int sid)
	{
		//Dim v As New NCS.VoltNew
		//v.cvoltArr = (New UnicodeEncoding()).GetString(SingleArrTobyteArr(mysig.yArr(0), mysig.yn(0)), 0, mysig.yn(0))
		//v.svoltArr = (New UnicodeEncoding()).GetString(SingleArrTobyteArr(mysig.yArr(1), mysig.yn(1)), 0, mysig.yn(0))
		//v.c2voltArr = (New UnicodeEncoding()).GetString(SingleArrTobyteArr(mysig.yArr(2), mysig.yn(2)), 0, mysig.yn(0))
		//v.s2voltArr = (New UnicodeEncoding()).GetString(SingleArrTobyteArr(mysig.yArr(3), mysig.yn(3)), 0, mysig.yn(0))
		//v.mtimeArr = (New UnicodeEncoding()).GetString(SingleArrTobyteArr(mysig.xArr, mysig.xn), 0, mysig.yn(0))
		//v.xn = mysig.xn
		//v.yn0 = mysig.yn(0)
		//v.yn1 = mysig.yn(1)
		//v.yn2 = mysig.yn(2)
		//v.yn3 = mysig.yn(3)
		//v.sampleid = sid
		//session.Save(v)
		//session.Flush()
	}
	public static void savesignew(ref NHibernate.ISession session, ref Sig mysig, int sid)
	{
        //NCS.VoltNew v = new NCS.VoltNew();
        //v.cvoltArr = SingleArrTobyteArr(ref mysig.yArr(0), ref mysig.yn(0));
        //v.svoltArr = SingleArrTobyteArr(ref mysig.yArr(1), ref mysig.yn(1));
        //v.c2voltArr = SingleArrTobyteArr(ref mysig.yArr(2), ref mysig.yn(2));
        //v.s2voltArr = SingleArrTobyteArr(ref mysig.yArr(3), ref mysig.yn(3));
        //v.mtimeArr = SingleArrTobyteArr(ref mysig.xArr, ref mysig.xn);
        //v.xn = mysig.xn;
        //v.yn0 = mysig.yn(0);
        //v.yn1 = mysig.yn(1);
        //v.yn2 = mysig.yn(2);
        //v.yn3 = mysig.yn(3);
        //v.sampleid = sid;
        //session.Save(v);
        //session.Flush();
	}
	public static void loadsignew_memo(ref NHibernate.ISession session, ref Sig mysig, int sid)
	{
		//Dim v As NCS.VoltNew
		//v = TryCast(session.Get(GetType(NCS.VoltNew), sid), NCS.VoltNew)
		//If Not v Is Nothing Then
		//    mysig.xn = v.xn
		//    mysig.yn(0) = v.yn0
		//    mysig.yn(1) = v.yn1
		//    mysig.yn(2) = v.yn2
		//    mysig.yn(3) = v.yn3
		//    bytearrtoSingleArr(v.mtimeArr, mysig.xArr, mysig.xn)
		//    bytearrtoSingleArr(v.cvoltArr, mysig.yArr(0), mysig.xn)
		//    bytearrtoSingleArr(v.svoltArr, mysig.yArr(1), mysig.xn)
		//    bytearrtoSingleArr(v.c2voltArr, mysig.yArr(2), mysig.xn)
		//    bytearrtoSingleArr(v.s2voltArr, mysig.yArr(3), mysig.xn)
		//End If
	}
	public static void loadsignew(ref NHibernate.ISession session, ref Sig mysig, int sid)
	{
        //NCS.VoltNew v = null;
        //v = session.Get(typeof(NCS.VoltNew), sid) as NCS.VoltNew;
        //if ((v != null)) {
        //    mysig.xn = v.xn;
        //    mysig.yn(0) = v.yn0;
        //    mysig.yn(1) = v.yn1;
        //    mysig.yn(2) = v.yn2;
        //    mysig.yn(3) = v.yn3;
        //    bytearrtoSingleArr(ref v.mtimeArr, ref mysig.xArr, mysig.xn);
        //    bytearrtoSingleArr(ref v.cvoltArr, ref mysig.yArr(0), mysig.xn);
        //    bytearrtoSingleArr(ref v.svoltArr, ref mysig.yArr(1), mysig.xn);
        //    bytearrtoSingleArr(ref v.c2voltArr, ref mysig.yArr(2), mysig.xn);
        //    bytearrtoSingleArr(ref v.s2voltArr, ref mysig.yArr(3), mysig.xn);
        //}
	}
	public static void bytearrtoSingleArr(ref byte[] bytetmp, ref object v, int n)
	{
		//If n < 1 Then Exit Sub
		//Dim x() As Double
		//ReDim x(n - 1)
		//Dim n1 As Integer
		//mymemcpy(x(0), bytetmp, n * 4)
		//bstrToarr1(bytetmp, x(0), n)

		//v = x
	}
}
